<template>
	<view class="pagesContent">
		<view class="title">文件类型</view>
		<view class="list">
			<view class="itemSpan" v-for="(item,index) in list" :key="item.title">
				<view class="item" @click="listrBoxClick(item, index)">
					<view class="left">
						<image class="icon" v-if="scanTypeIndex == index" :src="item.icon_select" mode=""></image>
						<image class="icon" v-else :src="item.icon" mode=""></image>
						<view class="subTitle">{{ item.title }}{{ scanTypeText }} </view>
					</view>
					<view class="right">
						<image class="icon" src="../../static/images/right.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view style=" height: 20rpx;"> </view>
		<adView></adView>
		<view class="btn" v-if="scanTypeIndex != -1" @click="scan"> 确定找回</view>
		<view class="btn btnDisable" v-else @click="hint"> 确定找回</view>
	</view>
</template>
<script>
	import {
		mapGetters,
		mapMutations,
		mapActions
	} from 'vuex'
	export default {
		data() {
			return {
				alllist: [{
						icon: "../../static/images/album_picture.png",
						icon_select: "../../static/images/album_picture_active.png",
						title: "相册",
						options: "system"
					},
					{
						icon: "../../static/images/wachat_picture.png",
						icon_select: "../../static/images/wachat_picture_active.png",
						title: "微信",
						options: "wechat"
					},
					{
						icon: "../../static/images/qq_picture.png",
						icon_select: "../../static/images/qq_picture_active.png",
						title: "QQ",
						options: "qq"
					},
					{
						icon: "../../static/images/other_picture.png",
						icon_select: "../../static/images/other_picture_active.png",
						title: "其他",
						options: "other",

					}
				],
				scanOption: null,
				scanType: null,
				scanTypeText: "图片",
				scanTypeIndex: -1,

				item: "",

				file: null,
			}
		},
		onShow() {
			if (!this.hasLogin) {
				this.goReLaunch("/pages/user/login")
			} else {
				// this.commitGetAppInfo();
				this.commitGetUserInfo();
				this.scanType = uni.getStorageSync("scanType")
				console.log("this.scanType", this.scanType)
				switch (this.scanType) {
					case "ALL_PICTURE":
						this.scanTypeText = "图片";
						break;
					case "PICTURE":
						this.scanTypeText = "图片";
						break;
					case "VIDEO":
						this.scanTypeText = "视频";
						break;
					case "AUDIO":
						this.scanTypeText = "音频";
						break;
					case "FILE":
						this.scanTypeText = "文档";
						break;
				}
				uni.setNavigationBarTitle({
					title: "扫描" + this.scanTypeText
				})
				console.log("this.alllist", this.alllist)

				console.log("this.scanType", this.scanType)
				if (this.scanType == 'AUDIO' || this.scanType == 'all_AUDIO' ||
					this.scanType == 'FILE' || this.scanType == 'all_FILE') {
					this.list = [this.alllist[1], this.alllist[2], this.alllist[3]]
				} else {
					this.list = this.alllist
				}
				console.log("list", this.list)

			}

		},
		computed: {
			...mapGetters(["hasLogin", "appVipSwitch", "userInfo"])
		},
		methods: {
			...mapActions(["commitGetAppInfo", "commitGetUserInfo"]),
			boxClick(item) {
				let this_ = this
				uni.setStorageSync("scanType", JSON.stringify(item))
				// #ifdef APP				
				this.FileManagerModule.listFileByType(item.options, item.type, (res) => {
					if (res == 'state_initialization_success') {
						this_.goPage(item.href, null)
					}
				})
				// #endif

				// #ifdef H5
				this_.goPage(item.href, null)
				// #endif


			},
			listrBoxClick(item, index) {
				this.scanTypeIndex = index
				this.scanOption = item.options
				uni.setStorageSync("scanOption", JSON.stringify(item.options))
				uni.setStorageSync("scanType", this.scanType)
			},
			hint() {
				this.text("请选择分类")
			},
			scan(item) {
				uni.setStorageSync("startInitType", "on")
				// #ifdef APP
				uni.setStorageSync("showHInt", "show")
				this.FileManagerModule.listFileByType(this.scanOption, this.scanType, (res) => {
					if (res == 'state_initialization_success') {
						this.goPage("/pages/files/index", null)
					}
				})
				// #endif
				// #ifdef H5
				this.goPage("/pages/files/index", null)
				// #endif
			}

		}
	}
</script>

<style lang="scss" scoped>
	.pagesContent {
		position: fixed;
		top: 40rpx;
		left: 0;
		right: 0;
		bottom: 0;
		border-radius: 40rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 32rpx 0px rgba(51, 114, 251, 0.27);
		border-radius: 48rpx 48rpx 0px 0px;

		.title {
			padding: 0 32rpx;
			height: 98rpx;
			line-height: 98rpx;
			font-size: 32rpx;
			font-weight: 600;
			color: #050505;

		}

		.list {
			.itemSpan {
				margin-bottom: 32rpx;

				.item {
					width: 686rpx;
					height: 120rpx;
					border-radius: 20rpx;
					margin: 0 auto 32rpx;
					background: #EEF3FF;

					.left {
						float: left;

						.icon {
							width: 60rpx;
							height: 60rpx;
							float: left;
							margin: 30rpx 34rpx 0 42rpx;
						}

						.subTitle {
							float: left;
							height: 120rpx;
							line-height: 120rpx;
							font-size: 28rpx;
							color: #454655;
						}
					}

					.right {
						float: right;
						margin: 50rpx 30rpx 0 0;

						.icon {
							width: 10rpx;
							height: 18rpx;
							display: block;
						}
					}
				}
			}
		}

		.btn {
			position: fixed;
			bottom: 40rpx;
			left: 50%;
			margin-left: -343rpx;
			width: 686rpx;
			height: 98rpx;
			background: linear-gradient(0deg, #1073F9, #3A8CFA);
			border-radius: 20rpx;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 98rpx;
			text-align: center;
		}

		.btnDisable {
			opacity: 0.3;
		}
	}
</style>